package renpyas3.view.instructions
{
	import flash.media.Sound;
	import renpyas3.model.RenpyPlayerModel;
	import renpyas3.view.RenpyPlayer;
	
	/**
	 * plays an mp3
	 */
	public class ViewInstruction_playMusic extends ViewInstruction
	{
		public static const NAME:String = "playMusic";
		
		public function ViewInstruction_playMusic() 
		{
			
		}
		
		/**
		 * execute a the code for this command, altering RenpyPlayerViewState
		 * @param	view  is the whole set of view state variables and operations that make up the VIEW
		 * @param	model the data needed to play a renpy novel
		 * @param	params   extra data for some instructions
		 */
		override public function execute(view:RenpyPlayer, model:RenpyPlayerModel, params:Object=null):void
		{
			var soundName:String = String(params);
			if (view.soundChannel)
			{
				view.soundChannel.stop();
			}
			if((model.currentScreen.soundsForThisScreen[soundName] as Sound).length >0)
			{
				view.soundChannel = model.currentScreen.soundsForThisScreen[soundName].play(0, int.MAX_VALUE); //loop
			}
			//all done in this command
			view.instructionsProcessor.instructionFinished();		
		}			
	}
}